* @param string|string[] ...$args strings to escape and glue together,
* or a single array of strings parameter
* @return string
- * @deprecated since 1.30 use MediaWiki\Shell::escape()
+ * @deprecated since 1.30 use MediaWiki\Shell\Shell::escape()
*/
function wfEscapeShellArg( ...$args ) {
return Shell::escape( ...$args );
* @file
*/
+use MediaWiki\Shell\Shell;
+
/**
* @ingroup Dump
*/
*/
function setup7zCommand( $file ) {
$command = "7za a -bd -si -mx=";
- $command .= wfEscapeShellArg( $this->compressionLevel ) . ' ';
- $command .= wfEscapeShellArg( $file );
+ $command .= Shell::escape( $this->compressionLevel ) . ' ';
+ $command .= Shell::escape( $file );
// Suppress annoying useless crap from p7zip
// Unfortunately this could suppress real error messages too
$command .= ' >' . wfGetNull() . ' 2>&1';
* @file
*/
+use MediaWiki\Shell\Shell;
+
/**
* @ingroup Dump
*/
*/
function __construct( $command, $file = null ) {
if ( !is_null( $file ) ) {
- $command .= " > " . wfEscapeShellArg( $file );
+ $command .= " > " . Shell::escape( $file );
}
$this->startCommand( $command );
$this->renameOrException( $newname );
if ( $open ) {
$command = $this->command;
- $command .= " > " . wfEscapeShellArg( $this->filename );
+ $command .= " > " . Shell::escape( $this->filename );
$this->startCommand( $command );
}
}
* @ingroup Media
*/
+use MediaWiki\Shell\Shell;
+
/**
* Generic handler for bitmap images
*
$rotation = isset( $params['disableRotation'] ) ? 0 : $this->getRotation( $image );
list( $width, $height ) = $this->extractPreRotationDimensions( $params, $rotation );
- $cmd = wfEscapeShellArg( ...array_merge(
+ $cmd = Shell::escape( ...array_merge(
[ $wgImageMagickConvertCommand ],
$quality,
// Specify white background color, will be used for transparent images
global $wgCustomConvertCommand;
# Variables: %s %d %w %h
- $src = wfEscapeShellArg( $params['srcPath'] );
- $dst = wfEscapeShellArg( $params['dstPath'] );
+ $src = Shell::escape( $params['srcPath'] );
+ $dst = Shell::escape( $params['dstPath'] );
$cmd = $wgCustomConvertCommand;
$cmd = str_replace( '%s', $src, str_replace( '%d', $dst, $cmd ) ); # Filenames
- $cmd = str_replace( '%h', wfEscapeShellArg( $params['physicalHeight'] ),
- str_replace( '%w', wfEscapeShellArg( $params['physicalWidth'] ), $cmd ) ); # Size
+ $cmd = str_replace( '%h', Shell::escape( $params['physicalHeight'] ),
+ str_replace( '%w', Shell::escape( $params['physicalWidth'] ), $cmd ) ); # Size
wfDebug( __METHOD__ . ": Running custom convert command $cmd\n" );
$retval = 0;
$err = wfShellExecWithStderr( $cmd, $retval );
$scaler = $this->getScalerType( null, false );
switch ( $scaler ) {
case 'im':
- $cmd = wfEscapeShellArg( $wgImageMagickConvertCommand ) . " " .
- wfEscapeShellArg( $this->escapeMagickInput( $params['srcPath'], $scene ) ) .
- " -rotate " . wfEscapeShellArg( "-$rotation" ) . " " .
- wfEscapeShellArg( $this->escapeMagickOutput( $params['dstPath'] ) );
+ $cmd = Shell::escape( $wgImageMagickConvertCommand ) . " " .
+ Shell::escape( $this->escapeMagickInput( $params['srcPath'], $scene ) ) .
+ " -rotate " . Shell::escape( "-$rotation" ) . " " .
+ Shell::escape( $this->escapeMagickOutput( $params['dstPath'] ) );
wfDebug( __METHOD__ . ": running ImageMagick: $cmd\n" );
$retval = 0;
$err = wfShellExecWithStderr( $cmd, $retval );
* @ingroup Media
*/
use MediaWiki\MediaWikiServices;
+use MediaWiki\Shell\Shell;
/**
* Handler for DjVu images
# Use a subshell (brackets) to aggregate stderr from both pipeline commands
# before redirecting it to the overall stdout. This works in both Linux and Windows XP.
- $cmd = '(' . wfEscapeShellArg(
+ $cmd = '(' . Shell::escape(
$wgDjvuRenderer,
"-format=ppm",
"-page={$page}",
if ( $wgDjvuPostProcessor ) {
$cmd .= " | {$wgDjvuPostProcessor}";
}
- $cmd .= ' > ' . wfEscapeShellArg( $dstPath ) . ') 2>&1';
+ $cmd .= ' > ' . Shell::escape( $dstPath ) . ') 2>&1';
wfDebug( __METHOD__ . ": $cmd\n" );
$retval = '';
$err = wfShellExec( $cmd, $retval );
* @ingroup Media
*/
+use MediaWiki\Shell\Shell;
+
/**
* Support for detecting/validating DjVu image files and getting
* some basic file metadata (resolution etc)
if ( isset( $wgDjvuDump ) ) {
# djvudump is faster as of version 3.5
# https://sourceforge.net/p/djvu/bugs/71/
- $cmd = wfEscapeShellArg( $wgDjvuDump ) . ' ' . wfEscapeShellArg( $this->mFilename );
+ $cmd = Shell::escape( $wgDjvuDump ) . ' ' . Shell::escape( $this->mFilename );
$dump = wfShellExec( $cmd );
$xml = $this->convertDumpToXML( $dump );
} elseif ( isset( $wgDjvuToXML ) ) {
- $cmd = wfEscapeShellArg( $wgDjvuToXML ) . ' --without-anno --without-text ' .
- wfEscapeShellArg( $this->mFilename );
+ $cmd = Shell::escape( $wgDjvuToXML ) . ' --without-anno --without-text ' .
+ Shell::escape( $this->mFilename );
$xml = wfShellExec( $cmd );
} else {
$xml = null;
}
# Text layer
if ( isset( $wgDjvuTxt ) ) {
- $cmd = wfEscapeShellArg( $wgDjvuTxt ) . ' --detail=page ' . wfEscapeShellArg( $this->mFilename );
+ $cmd = Shell::escape( $wgDjvuTxt ) . ' --detail=page ' . Shell::escape( $this->mFilename );
wfDebug( __METHOD__ . ": $cmd\n" );
$retval = '';
$txt = wfShellExec( $cmd, $retval, [], [ 'memory' => self::DJVUTXT_MEMORY_LIMIT ] );
* @file
* @ingroup Media
*/
+
+use MediaWiki\Shell\Shell;
use Wikimedia\ScopedCallback;
/**
// External command
$cmd = str_replace(
[ '$path/', '$width', '$height', '$input', '$output' ],
- [ $wgSVGConverterPath ? wfEscapeShellArg( "$wgSVGConverterPath/" ) : "",
+ [ $wgSVGConverterPath ? Shell::escape( "$wgSVGConverterPath/" ) : "",
intval( $width ),
intval( $height ),
- wfEscapeShellArg( $srcPath ),
- wfEscapeShellArg( $dstPath ) ],
+ Shell::escape( $srcPath ),
+ Shell::escape( $dstPath ) ],
$wgSVGConverters[$wgSVGConverter]
);
* @ingroup Media
*/
use MediaWiki\MediaWikiServices;
+use MediaWiki\Shell\Shell;
/**
* Handler for images that need to be transformed
function () use ( $method ) {
global $wgImageMagickConvertCommand;
- $cmd = wfEscapeShellArg( $wgImageMagickConvertCommand ) . ' -version';
+ $cmd = Shell::escape( $wgImageMagickConvertCommand ) . ' -version';
wfDebug( $method . ": Running convert -version\n" );
$retval = '';
$return = wfShellExecWithStderr( $cmd, $retval );
* @file
*/
+use MediaWiki\Shell\Shell;
+
/**
* Class encapsulating an image used in a ResourceLoaderImageModule.
*
if ( strpos( $wgSVGConverter, 'rsvg' ) === 0 ) {
$command = 'rsvg-convert';
if ( $wgSVGConverterPath ) {
- $command = wfEscapeShellArg( "$wgSVGConverterPath/" ) . $command;
+ $command = Shell::escape( "$wgSVGConverterPath/" ) . $command;
}
$process = proc_open(
* @ingroup Upload
*/
use MediaWiki\MediaWikiServices;
+use MediaWiki\Shell\Shell;
/**
* @defgroup Upload Upload related
if ( strpos( $command, "%f" ) === false ) {
# simple pattern: append file to scan
- $command .= " " . wfEscapeShellArg( $file );
+ $command .= " " . Shell::escape( $file );
} else {
# complex pattern: replace "%f" with file to scan
- $command = str_replace( "%f", wfEscapeShellArg( $file ), $command );
+ $command = str_replace( "%f", Shell::escape( $file ), $command );
}
wfDebug( __METHOD__ . ": running virus scan: $command \n" );
* @ingroup Maintenance
*/
+use MediaWiki\Shell\Shell;
+
/**
* Stream wrapper around 7za filter program.
* Required since we can't pass an open file resource to XMLReader->open()
} else {
return false;
}
- $arg = wfEscapeShellArg( $this->stripPath( $path ) );
+ $arg = Shell::escape( $this->stripPath( $path ) );
$command = "7za $options $arg";
if ( !wfIsWindows() ) {
// Suppress the stupid messages on stderr
$bash = ExecutableFinder::findInDefaultPaths( 'bash' );
if ( !wfIsWindows() && $bash ) {
$retval = false;
- $encPrompt = wfEscapeShellArg( $prompt );
+ $encPrompt = Shell::escape( $prompt );
$command = "read -er -p $encPrompt && echo \"\$REPLY\"";
- $encCommand = wfEscapeShellArg( $command );
- $line = wfShellExec( "$bash -c $encCommand", $retval, [], [ 'walltime' => 0 ] );
+ $encCommand = Shell::escape( $command );
+ $line = Shell::escape( "$bash -c $encCommand", $retval, [], [ 'walltime' => 0 ] );
if ( $retval == 0 ) {
return $line;
require_once __DIR__ . '/../includes/export/WikiExporter.php';
use MediaWiki\MediaWikiServices;
+use MediaWiki\Shell\Shell;
use MediaWiki\Storage\BlobAccessException;
use MediaWiki\Storage\SqlBlobStore;
use Wikimedia\Rdbms\IMaintainableDatabase;
if ( file_exists( "$IP/../multiversion/MWScript.php" ) ) {
$cmd = implode( " ",
- array_map( 'wfEscapeShellArg',
+ array_map( [ Shell::class, 'escape' ],
[
$this->php,
"$IP/../multiversion/MWScript.php",
'--wiki', wfWikiID() ] ) );
} else {
$cmd = implode( " ",
- array_map( 'wfEscapeShellArg',
+ array_map( [ Shell::class, 'escape' ],
[
$this->php,
"$IP/maintenance/fetchText.php",
<?php
+use MediaWiki\Shell\Shell;
+
require __DIR__ . '/../Maintenance.php';
class HHVMMakeRepo extends Maintenance {
$hhvm = $this->getOption( 'hhvm', 'hhvm' );
$verbose = $this->getOption( 'verbose', 3 );
- $cmd = wfEscapeShellArg(
+ $cmd = Shell::escape(
$hhvm,
'--hphp',
'--target', 'hhbc',
#!/usr/bin/hhvm -f
<?php
+use MediaWiki\Shell\Shell;
+
require __DIR__ . '/../Maintenance.php';
class RunHipHopServer extends Maintenance {
global $IP;
passthru(
- 'cd ' . wfEscapeShellArg( $IP ) . " && " .
- wfEscapeShellArg(
+ 'cd ' . Shell::escape( $IP ) . " && " .
+ Shell::escape(
'hhvm',
'-c', __DIR__."/server.conf",
'--mode=server',
* @version first release
*/
+use MediaWiki\Shell\Shell;
+
require_once __DIR__ . '/Maintenance.php';
/**
// Do not use wfShellWikiCmd, because mwdoc-filter.php is not
// a Maintenance script.
- $this->inputFilter = wfEscapeShellArg( [
+ $this->inputFilter = Shell::escape( [
$wgPhpCli,
$IP . '/maintenance/mwdoc-filter.php'
] );
* @ingroup Maintenance
*/
+use MediaWiki\Shell\Shell;
+
require_once __DIR__ . '/Maintenance.php';
/**
// in the pipe buffer. This can improve performance by up to a
// factor of 2.
global $wgDBuser, $wgDBserver, $wgDBpassword, $wgDBname;
- $cmd = 'mysql -u' . wfEscapeShellArg( $wgDBuser ) .
- ' -h' . wfEscapeShellArg( $wgDBserver ) .
- ' -p' . wfEscapeShellArg( $wgDBpassword, $wgDBname );
+ $cmd = 'mysql -u' . Shell::escape( $wgDBuser ) .
+ ' -h' . Shell::escape( $wgDBserver ) .
+ ' -p' . Shell::escape( $wgDBpassword, $wgDBname );
$this->output( "Using pipe method\n" );
$pipe = popen( $cmd, 'w' );
}
*/
use MediaWiki\MediaWikiServices;
+use MediaWiki\Shell\Shell;
if ( !defined( 'MEDIAWIKI' ) ) {
$optionsWithoutArgs = [ 'fix' ];
echo "Filtering XML dump...\n";
$exitStatus = 0;
passthru( 'mwdumper ' .
- wfEscapeShellArg(
+ Shell::escape(
"--output=file:$filteredXmlFileName",
"--filter=revlist:$revFileName",
$xml
use MediaWiki\Logger\LegacyLogger;
use MediaWiki\MediaWikiServices;
+use MediaWiki\Shell\Shell;
use Wikimedia\Rdbms\IDatabase;
$optionsWithArgs = RecompressTracked::getOptionsWithArgs();
* writing are all slow.
*/
function startReplicaProcs() {
- $cmd = 'php ' . wfEscapeShellArg( __FILE__ );
+ $cmd = 'php ' . Shell::escape( __FILE__ );
foreach ( self::$cmdLineOptionMap as $cmdOption => $classOption ) {
if ( $cmdOption == 'replica-id' ) {
continue;
} elseif ( in_array( $cmdOption, self::$optionsWithArgs ) && isset( $this->$classOption ) ) {
- $cmd .= " --$cmdOption " . wfEscapeShellArg( $this->$classOption );
+ $cmd .= " --$cmdOption " . Shell::escape( $this->$classOption );
} elseif ( $this->$classOption ) {
$cmd .= " --$cmdOption";
}
}
$cmd .= ' --child' .
- ' --wiki ' . wfEscapeShellArg( wfWikiID() ) .
- ' ' . wfEscapeShellArg( ...$this->destClusters );
+ ' --wiki ' . Shell::escape( wfWikiID() ) .
+ ' ' . Shell::escape( ...$this->destClusters );
$this->replicaPipes = $this->replicaProcs = [];
for ( $i = 0; $i < $this->numProcs; $i++ ) {